﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace P2P_Backup.tools
{
    public static class net
    {
        public class DataEventArgs : EventArgs
        {
            public DataEventArgs(string[] data) { this.data = data; }
            private string[] data;
            public string[] Data { get { return data; } }
        }

        public static byte[] getBytes(string text)
        {
            return Encoding.ASCII.GetBytes(text);
        }

        public static string[] getDataFromBytes(byte[] bytes,int bytesRead =0)
        {
            if (bytesRead == 0) bytesRead = bytes.Length;
            return Encoding.ASCII.GetString(bytes, 0, bytesRead).Split(' ');
        }

        public static IPEndPoint CreateIPEndPoint(IPAddress ip, string port)
        {
            int iPort;
            if (!int.TryParse(port, out iPort))
            {
                throw new FormatException("Invalid port");
            }
            return new IPEndPoint(ip, iPort);
        }
    }
}
